package com.DTC;

import java.io.Serializable;

public class IrisEntry implements Serializable{
    private Double sepalLen;         //花萼长度
    private Double sepalWidth;       //花萼宽度
    private Double petalLen;         //花瓣长度
    private Double petalWidth;       //花瓣宽度
    private Flower flowerType;      //花的种类
    public IrisEntry(String datas){
        try{
            String[] data = datas.split(",");
            sepalLen = Double.parseDouble(data[0]);
            sepalWidth = Double.parseDouble(data[1]);
            petalLen = Double.parseDouble(data[2]);
            petalWidth = Double.parseDouble(data[3]);
            switch (data[4]){
                case "Iris-setosa":{
                    flowerType = Flower.setosa;
                    break;
                }
                case "Iris-virginica":{
                    flowerType = Flower.virginica;
                    break;
                }
                case "Iris-versicolor":{
                    flowerType = Flower.versicolor;
                    break;
                }
            }
        } catch (Exception e){
            System.out.println("数据读取异常"+e);
        }
    }

    public Double[] getDataByArray(){
        Double[] data = {sepalLen,sepalWidth,petalLen,petalWidth};
        return data;
    }

    public Flower getFlowerType(){
        return flowerType;
    }

    public String toString(){
        System.out.println("["+sepalLen+","+sepalWidth+","+petalLen+","+petalWidth+"]\t type:"+flowerType);
        return "["+sepalLen+","+sepalWidth+","+petalLen+","+petalWidth+"]\t type:"+flowerType;
    }
}